const Controller = require('egg').Controller;
module.exports = class zeroyuanBuy extends Controller {
  async getGoodsList() {
    const { ctx, service } = this;
    // operationType 操作类型
    let { userId, page = 1, pageSize = 20, schedule, commodity_name, commodityid } = ctx.request.body

    // page = page,pageSize
    if (!ctx.helper.isNullFiled({ userId, page, pageSize })) {
      return
    };
    //
    let res = await service.admin.zeroyuanBuy.getGoodsList({ userId, page, pageSize, schedule, commodity_name, commodityid })
    ctx.body = res;
  }

  async getPhoto() {
    const { ctx, service } = this;
    let { userId, commodityid } = ctx.request.body;
    if (!ctx.helper.isNullFiled({ userId, commodityid })) {
      return
    };
    let res = await service.admin.zeroyuanBuy.getPhoto({ userId, commodityid })
    // return res
    ctx.body = res;
  }

  /**
   * 添加奖品
   */
  async addGoods() {
    const { ctx, service } = this;
    // operationType 操作类型
    let { userId, ccolumnid, commodity_name, commodity_desc, label_name, obtain_way, reason, market_price, productid, invest_money, sale_money, photo_path1, photo_path2 } = ctx.request.body

    // page = page,pageSize
    if (!ctx.helper.isNullFiled({ userId, ccolumnid, obtain_way, commodity_name, commodity_desc, label_name, reason, market_price, productid, invest_money, sale_money, photo_path1, photo_path2 })) {
      return
    };
    //
    let res = await service.admin.zeroyuanBuy.addGoods({ userId, ccolumnid, obtain_way, commodity_name, commodity_desc, label_name, reason, market_price, productid, invest_money, sale_money, photo_path1, photo_path2 })
    ctx.body = res;
  }


  /**
   * 添加奖品
   */
  async upDataGoods() {
    const { ctx, service } = this;
    // operationType 操作类型
    let {
      userId,
      ccolumnid,
      commodity_name,
      commodity_desc,
      label_name,
      reason,
      market_price,
      productid,
      invest_money,
      sale_money,
      commodityid,
      obtain_way,
      // photo_path,
      photo_path2,
      photo_path1,
      cphotoid,
      operationType
    } = ctx.request.body

    // page = page,pageSize
    if (!ctx.helper.isNullFiled({ userId, commodityid })) {
      return
    };
    //
    let res = await service.admin.zeroyuanBuy.upDataGoods({
      userId,
      commodityid,
      ccolumnid,
      commodity_name,
      commodity_desc,
      label_name,
      reason,
      market_price,
      productid,
      invest_money,
      sale_money,
      cphotoid,
      obtain_way,
      // photo_path,
      photo_path2,
      photo_path1,
      operationType
    })

    ctx.body = res;
  }

  /**
   * 0元购添加活动
   */
  async addActive() {
    const { ctx, service } = this;
    // operationType 操作类型
    let { userId, schedule, department, name, start_time, end_time, background_image_url, activity_abroad_url, is_use_coupon, goods_restrictions, channels } = ctx.request.body
    if (!ctx.helper.isNullFiled({ userId, schedule, department, name, start_time, end_time, activity_abroad_url, is_use_coupon, goods_restrictions, channels })) {
      return
    };
    //
    let res = await service.admin.zeroyuanBuy.addActive({ userId, schedule, department, name, start_time, end_time, background_image_url, activity_abroad_url, is_use_coupon, goods_restrictions, channels })
    ctx.body = res;
  }

  /**
   * 获取零元购活动列表
   */
  async getActiveList() {
    const { ctx, service } = this;
    // operationType 操作类型
    let { userId, page = 1, pageSize = 20, schedule, name, id, is_old_data } = ctx.request.body

    // page = page,pageSize
    if (!ctx.helper.isNullFiled({ userId })) {
      return
    };
    //
    let res = await service.admin.zeroyuanBuy.getActiveList({ userId, pageSize, page, name, id })
    ctx.body = res;

  }

  /**
   * 获取零元购活动渠道
   */
  async getChannels() {
    const { ctx, service } = this;
    // operationType 操作类型
    let { userId, activeId } = ctx.request.body

    // page = page,pageSize
    if (!ctx.helper.isNullFiled({ activeId})) {
      return
    };
    //
    let res = await service.admin.zeroyuanBuy.getChannels({ activeId, userId });
    ctx.body = res;

  }

}